! ******************************************************
! Input Parameters
! ******************************************************

module Input
    use Setup
    implicit none

contains

    subroutine setControl()
        implicit none

        ! Total Simulation time [s]
        TotalTime = 30.0d-12

        ! Output time [s]
        DumpPeriod = 1.0d-12

        ! Box Positions [cm]
        xMinBox = 0.0d0
        xMaxBox = 96.0d-5
        yMinBox = 0.0d0
        yMaxBox = 96.0d-5

        ! Cell Numbers per Characteristic Plasma Skin Depth
        Nx_unit = 2
        Ny_unit = 2

        ! Time Steps per Period of Ion Oscillation in Characteristic Plasma
        Nt_unit = 10/sqrt(1836.0)

        ! Characteristic Plasma Densities [cm^-3]
        neCharacter = 1.0d20 ! if neCharacter is not specified, please set L_unit
        L_unit = 0.0d0 ! [cm]
        
        ! Characteristic Plasma Temperature [eV]
        TeCharacter = 100
        ! Characteristic Magnetic field [Gs]
        B_unit = 0.0d0

        ! MPI Processors in Each Directions
        ppx = 2
        ppy = 2

        ! If Using Time Function
        UseTime = .true.

        ! If Using Boundary Function
        UseBoundary = .true.

        ! If Using Field Function
        UseField = .true.
        UseConv = .false.
        UseCAMCL = .true.
        UseCNPPC = .false.
        UseICS = .true.

        nt_b = 200
        electronTrap = 2.0d0
        ! convolution radius in Debye length
        CxDebye = 5.0
        CyDebye = 5.0

        ! If Using Plasma Function
        UsePlasma = .true.
        NSpecies = 2  ! Number of Ion Species

        ! If Using Injector Function
        UseInjector = .false.
        NInjector = 1 ! Number of Injector
        xMinInjector = .true.
        xMaxInjector = .false.
        yMinInjector = .false.
        yMaxInjector = .false.
    end subroutine setControl

    subroutine setBoundaries()
        implicit none

        ! Boundaries: 1-Open; 2-Periodic; 3-Reflect; 4-Thermal
        xMinBoundary = 2
        xMaxBoundary = 2
        yMinBoundary = 2
        yMaxBoundary = 2
    end subroutine setBoundaries

    subroutine setInjectors(x,y,Species,Injector)
        implicit none
        real(kind=8) :: x, y
        integer(kind=4) :: Species
        type(FluidParticle) :: Injector

        select case(Species)
        case(1)
            ! Ionization Degree
            Injector%Z = 1
            ! Mass Number
            Injector%A = 1
            ! Plasma velocity [cm/s]
            Injector%ux = 0.1*c
            ! Injector%ux = 0.0d0
            Injector%uy = 0.0d0
            Injector%uz = 0.0d0
            ! Ion Temperature [eV]
            Injector%Ti = 100
            ! Electron Temperature [eV]
            Injector%Te = 100
            ! Plasma Density [cm^-3]
            Injector%ni = 1.0d20
            ! if(y>0.04/SkinDepth .and. y<0.06/SkinDepth)then
            !     Injector%ni = 1.0d17
            ! else
            !     Injector%ni = 0.0d0
            ! end if
            ! Ion Pseudo-Particles per Cell
            Injector%ppc = 100
        case(2)
            Injector%Z = 1
            Injector%A = 1
            Injector%ux = 1.8d8
            Injector%uy = 0.0d0
            Injector%uz = 0.0d0
            Injector%Ti = 100
            Injector%Te = 40000
            Injector%ni = 1.0d17
            Injector%ppc = 100
        end select
    end subroutine setInjectors

    subroutine setPlasmas(x,y,Species,Plasma)
        implicit none
        real(kind=8) :: x, y
        integer(kind=4) :: Species
        type(FluidParticle) :: Plasma

        select case(Species)
        case(1)
            ! Ionization Degree
            Plasma%Z = 1
            ! Mass Number
            Plasma%A = 1
            ! Plasma velocity [cm/s]
            ! if(y>(yMaxBox-yMinBox)/2)then
            !     Plasma%ux = 0.1*c
            ! else
            !     Plasma%ux = -0.1*c
            ! end if
            ! Plasma%ux = 0.0d0
            Plasma%ux = 0.1*c
            Plasma%uy = 0.0d0
            Plasma%uz = 0.0d0
            ! Ion Temperature [eV]
            Plasma%Ti = 100
            ! Electron Temperature [eV]
            Plasma%Te = 100
            ! Plasma Density [cm^-3]
            ! if(x<=50/SkinDepth .or. x>=400/SkinDepth)then
            !     Plasma%ni = 1.0d13
            ! else
            !     Plasma%ni = 0.0d0
            ! end if
            Plasma%ni = 1.0d20
            ! Ion Pseudo-Particles per Cell
            Plasma%ppc = 100
        case(2)
            ! Ionization Degree
            Plasma%Z = 1
            ! Mass Number
            Plasma%A = 1
            ! Plasma velocity [cm/s]
            ! if(y>(yMaxBox-yMinBox)/2)then
            !     Plasma%ux = 0.1*c
            ! else
            !     Plasma%ux = -0.1*c
            ! end if
            ! Plasma%ux = 0.0d0
            Plasma%ux = -0.1*c
            Plasma%uy = 0.0d0
            Plasma%uz = 0.0d0
            ! Ion Temperature [eV]
            Plasma%Ti = 100
            ! Electron Temperature [eV]
            Plasma%Te = 100
            ! Plasma Density [cm^-3]
            ! if(x<=50/SkinDepth .or. x>=400/SkinDepth)then
            !     Plasma%ni = 1.0d13
            ! else
            !     Plasma%ni = 0.0d0
            ! end if
            Plasma%ni = 1.0d20
            ! Ion Pseudo-Particles per Cell
            Plasma%ppc = 100
        end select
    end subroutine setPlasmas

    subroutine setEfield(x,y,Efield)
        implicit none
        real(kind=8) :: x, y
        real(kind=8) :: Efield(3)

        ! Setting External Electric Field [statvolt/cm]
        Efield = 0.0d0
    end subroutine setEfield

    subroutine setBfield(x,y,Bfield)
        implicit none
        real(kind=8) :: x, y
        real(kind=8) :: Bfield(3)
      
        ! Setting External Magnetic Field [G]
        Bfield = 0.0d0
        ! Bfield(1) = 1.0d0
        !Bfield(2) = 0.5d0
    end subroutine setBfield

    subroutine setPhysics()
        implicit none

        ! If Including Lorentz's Law of Ion Motion
        UseLorentz = .true.

        ! If Including Ion-Weibel Instability
        UseWeibel = .true.

        ! If Including Faraday's Law of Electromagnetic Induction
        UseFaraday = .true.

        ! If Including General Ohm's Law
        UseOhm = .true.
    end subroutine setPhysics

    subroutine setOutput()
        implicit none

        ! Output Setting
        neDump = .true.       ! Density
        niDump = .true.
        uxDump = .true.       ! Velocity in X
        uyDump = .true.       ! Velocity in Y
        peDump = .true.       ! Electron Pressure
        ExDump = .true.       ! Electric Field in X
        EyDump = .true.       ! Electric Field in Y
        EzDump = .true.       ! Electric Field in Z
        BxDump = .true.       ! Magnetic Field in X
        ByDump = .true.       ! Magnetic Field in y
        BzDump = .true.       ! Magnetic Field in Z
        BwxDump = .true.      ! Ion-Weibel Magnetic Field in X
        BwyDump = .true.      ! Ion-Weibel Magnetic Field in y
        BwzDump = .true.      ! Ion-Weibel Magnetic Field in Z
        IonsDump = .true.     ! Particle Ions
    end subroutine setOutput
end module Input
